import java.util.Arrays;

/**
 * @author LKQ
 * @date 2022/2/20 12:44
 * @description 暴力，由题意从时间复杂度O(n^2) -> O(m * n (m <= 100))
 */
public class FormalSolution {
    public static void main(String[] args) {
        FormalSolution formalSolution = new FormalSolution();
        int[] tem = {73, 74, 75, 71, 69, 72, 76, 73};
        formalSolution.dailyTemperatures(tem);
    }
    public int[] dailyTemperatures(int[] temperatures) {
        int n = temperatures.length;
        int[] ans = new int[n];
        int[] next = new int[101];
        Arrays.fill(next, Integer.MAX_VALUE);
        for (int i = n - 1; i >= 0 ; i--) {
            int warmerIndex = Integer.MAX_VALUE;
            for (int t = temperatures[i] + 1; t <= 100; t++) {
                if (next[t] < warmerIndex) {
                    warmerIndex = next[t];
                }
            }
            if (warmerIndex < Integer.MAX_VALUE) {
                ans[i] = warmerIndex - i;
            }
            next[temperatures[i]] = i;
        }
        return ans;
    }
}
